import org.apache.commons.io.IOUtils
import org.apache.commons.fileupload.util.Streams
import org.apache.commons.fileupload.servlet.ServletFileUpload
import java.io.*;
import com.google.appengine.api.images.* 
import com.pobos.model.*
import com.google.appengine.api.datastore.*
import static com.google.appengine.api.datastore.FetchOptions.Builder.*




def idConcello = params.id

if (idConcello) {
	
	 //Obtiene la entity del concello
	 def key = KeyFactory.createKey(Concello.class.simpleName, Long.parseLong(idConcello))
	 Entity concelloEntity = datastore.get(key)	
	 
	 request.concello = concelloEntity
	 forward '/verConcello.gtpl'
	 
}



def obtenUsuarioSesion(String usuarioSesion) {
	def query = new Query(Usuario.class.simpleName)
	query.addFilter("nome", Query.FilterOperator.EQUAL, usuarioSesion)
	def preparedQuery = datastore.prepare(query)
	
	if (preparedQuery.countEntities() == 0) {
		return null;
	} else {
		if(preparedQuery.countEntities() > 1){
			return preparedQuery.asList(withLimit(1))[0]
		}else{
			return preparedQuery.asSingleEntity()
		}
	}
	
}   

def obtenPerfil(Long id) {
	def key = KeyFactory.createKey("Perfil", id)			
	return datastore.get(key)
}  



